//
//  UIView+MHExtension.m
//  MeiHengInvestment
//
//  Created by 刘家俊 on 17/4/24.
//  Copyright © 2017年 Andrew. All rights reserved.
//

#import "UIView+MHExtension.h"

@implementation UIView (MHExtension)

- (CGSize)mh_size
{
    return self.frame.size;
}

- (void)setMh_size:(CGSize)mh_size
{
    CGRect frame = self.frame;
    frame.size = mh_size;
    self.frame = frame;
}

- (CGFloat)mh_width
{
    return self.frame.size.width;
}

- (void)setMh_width:(CGFloat)mh_width
{
    CGRect frame = self.frame;
    frame.size.width = mh_width;
    self.frame = frame;
}

- (CGFloat)mh_height
{
    return self.frame.size.height;
}

- (void)setMh_height:(CGFloat)mh_height
{
    CGRect frame = self.frame;
    frame.size.height = mh_height;
    self.frame = frame;
}

- (CGFloat)mh_x
{
    return self.frame.origin.x;
}

- (void)setMh_x:(CGFloat)mh_x
{
    CGRect frame = self.frame;
    frame.origin.x = mh_x;
    self.frame = frame;
}

- (CGFloat)mh_y
{
    return self.frame.origin.y;
}

- (void)setMh_y:(CGFloat)mh_y
{
    CGRect frame = self.frame;
    frame.origin.y = mh_y;
    self.frame = frame;
}

- (CGFloat)mh_centerX
{
    return self.center.x;
}

- (void)setMh_centerX:(CGFloat)mh_centerX
{
    CGPoint center = self.center;
    center.x = mh_centerX;
    self.center = center;
}

- (CGFloat)mh_centerY
{
    return self.center.y;
}

- (void)setMh_centerY:(CGFloat)mh_centerY
{
    CGPoint center = self.center;
    center.y = mh_centerY;
    self.center = center;
}

- (CGFloat)mh_right
{
    return CGRectGetMaxX(self.frame);
}

- (void)setMh_right:(CGFloat)mh_right
{
    self.mh_x = mh_right - self.mh_width;
}

- (CGFloat)mh_bottom
{
    return CGRectGetMaxY(self.frame);
}

- (void)setMh_bottom:(CGFloat)mh_bottom
{
    self.mh_y = mh_bottom - self.mh_height;
}

+ (instancetype)mh_viewFormXib
{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].lastObject;
}

- (BOOL)mh_intersectWithView:(UIView *)view
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    CGRect selfRect = [self convertRect:self.bounds toView:window];
    CGRect viewRecg = [view convertRect:view.bounds toView:window];
    return CGRectIntersectsRect(selfRect, viewRecg);
    
}

@end
